package com.learn;


import com.google.common.collect.Lists;

import java.util.*;
import java.util.stream.Collectors;

public class TestJava8 {
    public static void main(String[] args) {
        //java 8
        /*new Thread(
                ()-> System.out.println("hi java 8")
        );*/
        /*Action action = System.out::println;
        action.execute("Hi");
        test(System.out::println,"hi");*/
        /*List<String> list = new ArrayList<>();
        list.add("a");
        list.add("c");
        list.add("b");

        //String concatenated = list.t.reduce("", String::concat)
        //System.out.println( list.stream().collect() );

        list.forEach(o -> System.out.println(o));

        System.out.println(list);*/
        ArrayList<Dish> dishes = Lists.newArrayList(
                new Dish("pork", false, 800, "MEAT"),
                new Dish("beef", false, 700, "MEAT"),
                new Dish("chicken", false, 400, "MEAT"),
                new Dish("french fries", true, 530, "OTHER"),
                new Dish("rice", true, 350, "OTHER"),
                new Dish("season fruit", true, 120, "OTHER"),
                new Dish("pizza", true, 550, "OTHER"),
                new Dish("prawns", false, 300, "FISH"),
                new Dish("salmon", false, 450, "FISH")
        );
        /*Optional<Dish> maxCalories = dishes.stream().max(Comparator.comparingInt(Dish::getCalories));
        Optional<Dish> minCalories = dishes.stream().min(Comparator.comparingInt(Dish::getCalories));
        Double avgCalories = dishes.stream().collect(Collectors.averagingInt(Dish::getCalories));

        System.out.println(maxCalories.get().getName());
        System.out.println(minCalories.get().getName());
        System.out.println(avgCalories);*/

        /*String join1 = dishes.stream().map(Dish::getName).collect(Collectors.joining("|"));
        System.out.println(join1);

        int sum = dishes.stream().mapToInt(Dish::getCalories).sum();
        System.out.println(sum);*/

    }
    static void test(Action action, String str){
        action.execute(str);
    }

}

class Dish{
    private String name;
    private int calories;
    private boolean a;
    private String b;

    public Dish(String name,boolean a, int calories,String b) {
        this.name = name;
        this.a = a;
        this.calories = calories;
        this.b = b;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCalories() {
        return calories;
    }

    public void setCalories(int calories) {
        this.calories = calories;
    }

    public boolean isA() {
        return a;
    }

    public void setA(boolean a) {
        this.a = a;
    }

    public String getB() {
        return b;
    }

    public void setB(String b) {
        this.b = b;
    }
}

interface Action<T> {
    public void execute(T t);
}
